package com.qiwx.pigeon.presenter;

import com.qiwx.pigeon.base.BasePresenter;
import com.qiwx.pigeon.base.IBaseView;
import com.qiwx.pigeon.data.network.ApiManager;
import com.qiwx.pigeon.data.network.BaseResponse;
import com.qiwx.pigeon.data.network.ResponseSubscriber;
import com.qiwx.pigeon.data.params.GetMemberParam;
import com.qiwx.pigeon.data.params.UpdatePwdParam;
import com.qiwx.pigeon.data.vo.EmployBean;
import com.qiwx.pigeon.data.vo.pageinfo.PageInfo;
import com.qiwx.pigeon.viewinterface.IUserManagerView;

import java.lang.ref.WeakReference;
import java.util.Map;

import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * @description
 * @Author qiwx
 * @Date 2020-06-06 11:22
 **/
public class UserManagerPresenter extends BasePresenter<IUserManagerView> {
    public UserManagerPresenter(WeakReference<IUserManagerView> from) {
        super(from);
    }

    public UserManagerPresenter(IUserManagerView from) {
        super(from);
    }

    //添加下属账号
    public void addEmployer(EmployBean param) {
        ApiManager.getApiServer().addEmployer(param)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new ResponseSubscriber<BaseResponse>(true) {
                    @Override
                    public IBaseView getIView() {
                        return getView();
                    }

                    @Override
                    public void onSuccess(BaseResponse response) {
                        getView().onSuccess(response.getStatus());
                    }

                    @Override
                    public void onFailure(String error) {
                        getView().onFailure(error);
                    }
                });
    }
    //获取下属账号
    public void getMembers(GetMemberParam param) {
        ApiManager.getApiServer().getMembersByPage(param)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new ResponseSubscriber<BaseResponse<PageInfo<EmployBean>>>(true) {
                    @Override
                    public IBaseView getIView() {
                        return getView();
                    }

                    @Override
                    public void onSuccess(BaseResponse<PageInfo<EmployBean>> response) {
                        getView().onMemberSuccess(response.data);
                    }

                    @Override
                    public void onFailure(String error) {
                        getView().onFailure(error);
                    }
                });
    }
    //修改密码
    public void updatePwd(UpdatePwdParam param) {
        ApiManager.getApiServer().updatePwd(param)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new ResponseSubscriber<BaseResponse>(true) {
                    @Override
                    public IBaseView getIView() {
                        return getView();
                    }

                    @Override
                    public void onSuccess(BaseResponse response) {
                        getView().onSuccess(response.getStatus());
                    }

                    @Override
                    public void onFailure(String error) {
                        getView().onFailure(error);
                    }
                });
    }
}
